<template>
  <div>
    <ul>
      <li ref="first">
        <router-link to="/contacts/all">All_contacts</router-link>
      </li>
      <li><router-link to="/contacts/alice">Alice</router-link></li>
      <li><router-link to="/contacts/bob">Bob</router-link></li>
    </ul>
    <button @click="changeEvent">随机显示</button>
    <!-- 二级路由出口 -->
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  data() {
    return {
      random: 0,
    };
  },
  methods: {
    changeEvent() {
      this.random = Math.floor(Math.random() * 3);
      if (this.random === 0) {
        this.$router.push("/contacts/all");
      } else if (this.random === 1) {
        this.$router.push("/contacts/alice");
      } else if (this.random === 2) {
        this.$router.push("/contacts/bob");
      }
    },
  },
};
</script>

<style scoped>
a {
  text-decoration: none;
}
</style>
